package com.aaa.service.impl;

import com.aaa.dao.CardDao;
import com.aaa.dao.impl.CardDaoImpl;
import com.aaa.entity.Card;
import com.aaa.entity.Duo;
import com.aaa.service.CardService;
import com.aaa.util.BusinessException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CardServiceImpl implements CardService {
    CardDao cardDao = new CardDaoImpl();

    @Override
    public int changeStatus(Card card) {
        return cardDao.changeStatus(card);
    }


    @Override
    public Map<String, Object> getAllCardList(Integer pageNumber, Integer pageSize, String searchId, String searchName)throws Exception {
        if (pageNumber == null || pageNumber == 0) {
            throw new BusinessException("当前页数不能为空");
        }
        if (pageSize == null || pageSize == 0) {
            throw new BusinessException("每页条数不能为空");
        }
        pageNumber = (pageNumber - 1) * pageSize;
        // 当前页码数据
        List<Card> list = cardDao.getAllCardList(pageNumber,pageSize,searchId,searchName);

        // 总页数
        int count = cardDao.getAllCardInfoCount(searchId,searchName);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);
        return map;
    }

    @Override
    public List<Duo> getAllSlotCard(String searchId) {
        return cardDao.getAllSlotCard(searchId);
    }

    @Override
    public Map<String, Object> getAllSlotCardList(Integer pageNumber, Integer pageSize,String searchId) throws Exception {
        if (pageNumber == null || pageNumber == 0) {
            throw new BusinessException("当前页数不能为空");
        }
        if (pageSize == null || pageSize == 0) {
            throw new BusinessException("每页条数不能为空");
        }
        pageNumber = (pageNumber - 1) * pageSize;
        // 当前页码数据
        List<Duo> list = cardDao.getAllSlotCardList(pageNumber,pageSize,searchId);
        // 总页数
        int count = cardDao.getAllSlotCardInfoCount(searchId);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);
        return map;
    }
}
